package com.fit.pages;

import java.util.LinkedList;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.beans.MaterialBean;
import com.fit.interfaces.BuldingMaterials;
import com.fit.interfaces.Buy;
import com.fit.interfaces.User;
import com.fit.service.BuldingsMaterials;


public class EntryMaterial {
	
	@Property
	@Persist
	private BuldingMaterials buldingmaterials;

	@Inject
	private BuldingsMaterials buldingsmaterials;
	
	@SetupRender
	public void createObject() {
		buldingmaterials = new MaterialBean();
		buldingmaterials.setBuy(new LinkedList<Buy>());
	}

	void onSuccess() {
		buldingsmaterials.save(buldingmaterials);
	}
	
	@SessionState
	private User user;

	private boolean userExists;
	
	public User getUser() {
		return user;
	}
	
	Object onActivate() {
		if (!userExists) return Login.class;
		return null;
	}
	
	
//	private String MaterialType = "Type of material: ";
//	private String MaterialModel = "Model of material: ";
//	private String MaterialShortDescription = "Short description material: ";
//	
//	@InjectPage
//	private ViewMaterial viewMaterial;
//	
//	@InjectPage
//	private Error errorPage;
//	
//	@OnEvent (value="submit", component="MaterialInputForm")
//	Object onFromSubmit() {
//		BuldingMaterials materialM = new MaterialBean();
//		materialM.setBuy(new LinkedList<Buy>());
//		materialM.setType(MaterialType);
//		materialM.setModel(MaterialModel);
//		materialM.setShortDescription(MaterialShortDescription);
//		if (materialM.getType()==null || materialM.getModel()==null) {
//            errorPage.setError("Nije moguce dodati novu knjigu bez naslova ili autora knjige!");
//            return errorPage;
//	}
//		viewMaterial.setSingleMaterial(materialM);
//        return viewMaterial;
//        }
//
//
//	public String getMaterialType() {
//		return MaterialType;
//	}
//	
//	public void setMaterialType(String watchType) {
//		this.MaterialType = watchType;
//	}
//
//	public String getMaterialModel() {
//		return MaterialModel;
//	}
//
//	public void setMaterialModel(String MaterialModel) {
//		this.MaterialModel = MaterialModel;
//	}
//
//	public String getMaterialShortDescription() {
//		return MaterialShortDescription;
//	}
//
//	public void setMaterialShortDescription(String MaterialShortDescription) {
//		this.MaterialShortDescription = MaterialShortDescription;
//	}

}
